package com.jf.demo;

import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.RequestParams;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.sys.android.util.FinalUntil;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.TextView;
import android.widget.Toast;

public class MyOrderEvaluation extends Activity {

	private TextView t1;
	private TextView t2;
	private TextView t3;
	
	private CheckBox checkBox1;
	private EditText editText1;
	private RatingBar ratingBar1;
	
	private SharedPreferences useShare;
	private String userId;
	@Override
	protected void onCreate(Bundle arg0) {
		// TODO Auto-generated method stub
		super.onCreate(arg0);
		setContentView(R.layout.my_order_evaluation);
		Intent intent = getIntent();
		t1 = (TextView)findViewById(R.id.textView2);
		t1.setText(intent.getStringExtra("gs"));
		t2 = (TextView)findViewById(R.id.textView5);
		t2.setText(intent.getStringExtra("dh"));
		t3 = (TextView)findViewById(R.id.textView7);
		t3.setText(intent.getStringExtra("kdy"));
		checkBox1 = (CheckBox)findViewById(R.id.checkBox1);
		editText1 = (EditText)findViewById(R.id.editText1);
		ratingBar1 = (RatingBar)findViewById(R.id.ratingBar1);
		useShare = getSharedPreferences("userInfo", MODE_PRIVATE);
		userId = useShare.getString("username", "");
	}
	
	public void finishOrderEvaluation(View v){
		this.finish();
	}
	
	public void saveEva(View v){
		Boolean bl = checkBox1.isChecked();
		Float f= ratingBar1.getRating();
		
		
		RequestParams params = new RequestParams();
		params.addQueryStringParameter("userID", userId);
		params.addQueryStringParameter("orderID", t2.getText().toString());
		params.addQueryStringParameter("assessGrade", f.toString());
		params.addQueryStringParameter("whetherComplaint", bl.toString());
		params.addQueryStringParameter("assessContent", editText1.getText().toString());
		
		HttpUtils http = new HttpUtils();
		http.send(HttpMethod.POST, FinalUntil.ServerAddress+"saveAssess",
				params, new RequestCallBack<String>() {

					@Override
					public void onFailure(HttpException arg0, String arg1) {
						// TODO Auto-generated method stub
						Log.i("MyAlreadyOrder", arg1);
					}

					@Override
					public void onSuccess(ResponseInfo<String> arg0) {
						Toast.makeText(MyOrderEvaluation.this, "信息保存成功", 0).show();
						MyOrderEvaluation.this.finish();
					}
		});
	}
}
